#define DEBUG
#include <cstdio>
#define MAXN 1500
#define MAXM 1500

using namespace std;

class Matrix {
public:
  int n, a[MAXM+1];

  static void mul(Matrix *a, Matrix *b, Matrix *c, int m) {
    static int book[MAXM+1], ver;
    ver++;
    c->n=0;
    for (int i=1; i<=a->n; i++) {
      for (int j=1; j<=b->n; j++) {
	if (book[a->a[i]*b->a[j]%m]!=ver) {
	  c->a[++c->n] = a->a[i]*b->a[j]%m;
	  book[c->a[c->n]]=ver;
	}
      }
    }
  }
};

void qpower(const Matrix *a, long long n, int m, Matrix *ret) {
  Matrix temp[2], s[2];
  temp[0] = *a, s[0].n=1, s[0].a[1] = 1;
  int i, j;
  for (i=j=1; n>1; n/=2) {
    if (n&1) {
      Matrix::mul(&s[(j-1)%2], &temp[(i-1)%2], &s[j%2], m);
      j++;
    }
    Matrix::mul(&temp[(i-1)%2], &temp[(i-1)%2], &temp[i%2], m);
    i++;
  }
  Matrix::mul(&temp[(i-1)%2], &s[(j-1)%2], ret, m);
}

void qsort(int *a, int l, int r) {
  int i=l, j=r, mid=a[(l+r)/2], temp;
  for (; i<=j; ) {
    for (; a[j]>mid; j--);
    for (; a[i]<mid; i++);
    if (i<=j) {
      temp=a[i], a[i]=a[j], a[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    qsort(a, i, r);
  }
  if (j>l) {
    qsort(a, l, j);
  }
}

int main() {
#ifdef DEBUG
  freopen("3156.in", "r", stdin);
  freopen("3156.out", "w", stdout);
#endif

  long long k;
  int m, n;
  scanf("%lld %d %d", &k, &m, &n);
  static Matrix t, ans;
  t.n=n;
  for (int i=1; i<=n; i++) {
    scanf("%d", t.a+i);
  }

  qpower(&t, k, m, &ans);
  qsort(ans.a, 1, ans.n);
  for (int i=1; i<=ans.n; i++) {
    printf("%d ", ans.a[i]);
  }

  fcloseall();
  return 0;
}
